Ext.apply(Ext.form.VTypes, {
            RecidT : function(_v) {
                return /(^[0-9]{7}$)/
                        .test(_v);
            },
            RecidTText : "请注意记录号格式必须为7位整数"
        }); // 自定义的 vtype

Ext.onReady(function() {
	Ext.QuickTips.init(); // 如要实现错误提示，需要此初始化
	Ext.form.Field.prototype.msgTarget = 'side';

	var height = this.document.documentElement.clientHeight;
	var width = this.document.documentElement.clientWidth;


	// 问题区域开始
	var problemsm = new Ext.grid.CheckboxSelectionModel();

	var problemcm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),
			problemsm, {
				header : "问题编号",
				dataIndex : "eventcauseID",
				sortable : true
			}, {
				header : "地点编号",
				dataIndex : "areaID",
				sortable : true
			}, {
				header : "纪录编号",
				dataIndex : "recID",
				sortable : true
			}, {
				header : "问题来源编号",
				dataIndex : "eventsrcID",
				sortable : true
			}, {
				header : "问题来源",
				dataIndex : "eventsrc",
				sortable : true
			}, {
				header : "问题子来源",
				dataIndex : "eventsubsrc",
				sortable : true
			}, {
				header : "问题类别",
				dataIndex : "eventtype",
				sortable : true
			}, {
				header : "大类",
				dataIndex : "bigcategory",
				sortable : true
			}, {
				header : "小类",
				dataIndex : "smallcategory",
				sortable : true
			}, {
				header : "子类",
				dataIndex : "subcategory",
				sortable : true
			}, {
				header : "问题状态",
				dataIndex : "eventstate",
				sortable : true
			}, {
				header : "当前阶段名称",
				dataIndex : "currentstatename",
				sortable : true
			}]);

	var aaProxy = new Ext.data.HttpProxy({
				url : "problem",
				method : "GET"
			});

	var searchProxy = new Ext.data.HttpProxy({
				url : "problem?method=search",
				method : "POST"
			});
	var problemstore = new Ext.data.Store({
				proxy : aaProxy,
				reader : new Ext.data.JsonReader({})
			});
	problemstore.load();
	var problempp = new Ext.grid.GridPanel({
		id : 'problempp',
		title : '问题信息',
		region : 'center',
		autoShow : true,
		height : height,
		width : width,

		split : true,
		minSize : 175,
		maxSize : 400,
		frame : true,
		columnLines : true,
		sm : problemsm,
		store : problemstore,
		cm : problemcm,
		tbar : [{
			pressed : false,
			text : '添加问题',
			icon : "static/images/add.gif",
			handler : function() {
				var TproblemID = new Ext.form.Field({
							id : 'eventcauseID',
							name : 'eventcauseID',
							allowBlank : true,
							fieldLabel : "问题编号"
						});

				var TareaID = new Ext.form.Field({
							id : 'areaID',
							name : 'areaID',
							allowBlank : true,
							fieldLabel : "发生地点编号"
						});

				var TrecID = new Ext.form.Field({
							id : 'recID',
							name : 'recID',
							allowBlank : true,
							fieldLabel : "纪录编号"
						});

				var TeventsrcID = new Ext.form.Field({
							id : 'eventsrcID',
							name : 'eventsrcID',
							allowBlank : true,
							fieldLabel : "问题来源编号"
						});

				var Teventsrc = new Ext.form.Field({
							id : 'eventsrc',
							name : 'eventsrc',
							allowBlank : true,
							fieldLabel : "问题来源"
						});
				var Teventsubsrc = new Ext.form.Field({
							id : 'eventsubsrc',
							name : 'eventsubsrc',
							allowBlank : true,
							fieldLabel : "问题子来源"
						});

				var Teventtype = new Ext.form.Field({
							id : 'eventtype',
							name : 'eventtype',
							allowBlank : true,
							fieldLabel : "问题类别"
						});

				var Tbigcategory = new Ext.form.Field({
							id : 'bigcategory',
							name : 'bigcategory',
							allowBlank : true,
							fieldLabel : "大类"
						});

				var Tsmallcategory = new Ext.form.Field({
							id : 'smallcategory',
							name : 'smallcategory',
							allowBlank : true,
							fieldLabel : "小类"
						});

				var Tsubcategory = new Ext.form.Field({
							id : 'subcategory',
							name : 'subcategory',
							allowBlank : true,
							fieldLabel : "子类"
						});

				var Tcurrentstatename = new Ext.form.ComboBox({
							id : 'currentstatename',
							editable : false,
							typeAhead : true,
							triggerAction : 'all',
							lazyRender : true,
							emptyText : '请选择当前阶段名称',
							// autoWidth : true,
							width : 150,
							mode : 'local',
							/** Fix此处按需改成googlesuggest模式 */
							store : new Ext.data.ArrayStore({
										id : 1,
										fields : ['currentstatename'],
										data : [['信息中心（受理）'], ['信息中心（不受理）'],
												['信息中心（提交中）']]
									}),
							valueField : 'currentstatename',
							displayField : 'currentstatename'

						});

				var Teventstate = new Ext.form.Field({
							id : 'eventstate',
							name : 'eventstate',
							allowBlank : true,
							fieldLabel : "问题状态"
						});

				var formp = new Ext.form.FormPanel({
					title : "问题添加",
					closable : true,
					labelAlign : "right",
					buttonAlign : "center",
					// width : 350,
					// height : 500,
					autoHeight : true,
					autoWidth : true,
					frame : true,
					split : true,
					items : [TproblemID, TareaID, TrecID, TeventsrcID,
							Teventsrc, Teventsubsrc, Teventtype, Tbigcategory,
							Tsmallcategory, Tsubcategory, Teventstate,
							Tcurrentstatename],
					url : "problem?method=add",
					method : "post",
					buttons : [{
						text : "确定",
						icon : "extjsLib/resources/static/images/default/dd/disk.png",
						handler : function() {
							formp.getForm().submit({
										success : function(form, action) {
											var msg = action.result.msg;
											if (msg == "yes") {
												problemstore.reload();
												Ext.Msg.alert("成功",
														"恭喜，问题信息添加成功！");
												addwin.close();
											}
											if (msg == "no") {
												Ext.Msg.alert("失败",
														"问题号重复或不存在！");
											}
											// store.reload();
										},
										failure : function(response) {
											Ext.Msg
													.alert("失败",
															"对不起，问题信息添加异常！");
										}
									});
						}
					}, {
						text : "重置",
						icon : "extjsLib/resources/static/images/default/dd/delete.gif",
						handler : function() {
							formp.getForm().reset();
						}
					}]
				});
				var addwin = new Ext.Window({
							title : "",
							width : 350,
							// height : 350,
							closeAction : "close",
							closeable : true,
							items : formp,
							collapsible : true,
							autoHeight : true,
							modal : true
						});
				addwin.show();
			}
		}, {
			xtype : "tbseparator"
		}, {
			pressed : false,
			text : '问题删除',
			icon : "static/images/cross.gif",
			handler : function() {
				var selModel = problempp.getSelectionModel();
				if (selModel.hasSelection()) {
					Ext.Msg.confirm("确认", "您确定要删除选择的记录吗？", function(btn) {
						if (btn == "yes") {
							var records = selModel.getSelections();
							var ids = [];
							for (var i = 0; i < records.length; i++) {
								ids.push(records[i].get("problemID")); // 获取选择的条目id
							}
							Ext.Ajax.request({
										url : "problem?method=delete",
										params : {
											ids : ids
										},
										method : "post",
										success : function(form, action) {
											Ext.MessageBox.alert("结果", "删除成功！");
											problemstore.reload();
										},
										failure : function() {
											var messagestr = response.result.msg;
											alert(messagestr);
											problemstore.reload();
											// Ext.Msg
											// .alert(
											// "结果",
											// "对不起，删除异常！");
										}
									});

						}
					});
				} else {
					Ext.Msg.alert("错误", "请选择要删除的行！");
				}
			}
		}, {
			xtype : "tbseparator"
		}, {
			pressed : false,
			text : '修改问题信息',
			icon : "static/images/details.gif",
			handler : function() {
				// Ext.Msg.alert("修改");
				var selModel = problempp.getSelectionModel();
				var record;
				if (!selModel.hasSelection()) {
					Ext.Msg.alert("错误", "请选择要修改的行！");
				} else if (selModel.getSelections().length > 1) {
					Ext.Msg.alert("错误", "一次只能选择一行！");
				} else {
					record = selModel.getSelected();

					var TproblemID = new Ext.form.Field({
								id : 'eventcauseID',
								name : 'eventcauseID',
								allowBlank : true,
								fieldLabel : "问题编号",
                                value:record.get('eventcauseID'),
								readOnly:true
							});

					var TareaID = new Ext.form.Field({
								id : 'areaID',
								name : 'areaID',
								allowBlank : true,
								fieldLabel : "发生地点编号"
							});
					var TrecID = new Ext.form.TextField({
								id : 'recID',
								name : 'recID',
								allowBlank : true,
								fieldLabel : "纪录编号",
                                value:record.get('recID'),
                                vtype:'RecidT'
							});
					var TeventsrcID = new Ext.form.Field({
								id : 'eventsrcID',
								name : 'eventsrcID',
								allowBlank : true,
								fieldLabel : "问题来源编号"
							});

					var Teventsrc =new Ext.form.ComboBox({
                                id : 'eventsrc',
                                editable : false,
                                fieldLabel:'问题来源',
                                typeAhead : true,
                                triggerAction : 'all',
                                lazyRender : true,
                                emptyText : '请选择问题来源',
                                // autoWidth : true,
                                width : 150,
                                mode : 'local',
                                /** Fix此处按需改成googlesuggest模式 */
                                store : new Ext.data.ArrayStore({
                                            id : 1,
                                            fields : ['eventsrc'],
                                            data : [['信息采集员上报'],
                                                    ['举报'],
                                                    ['其他']]
                                        }),
                                valueField : 'eventsrc',
                                displayField : 'eventsrc'

                            }); 

					var Teventsubsrc = new Ext.form.Field({
								id : 'eventsubsrc',
								name : 'eventsubsrc',
								allowBlank : true,
								fieldLabel : "问题子来源"
							});

					var Teventtype = new Ext.form.Field({
								id : 'eventtype',
								name : 'eventtype',
								allowBlank : true,
								fieldLabel : "问题类别"
							});

					var Tbigcategory = new Ext.form.Field({
								id : 'bigcategory',
								name : 'bigcategory',
								allowBlank : true,
								fieldLabel : "大类"
							});

					var Tsmallcategory = new Ext.form.Field({
								id : 'smallcategory',
								name : 'smallcategory',
								allowBlank : true,
								fieldLabel : "小类"
							});

					var Tsubcategory = new Ext.form.Field({
								id : 'subcategory',
								name : 'subcategory',
								allowBlank : true,
								fieldLabel : "子类"
							});

					var Tcurrentstatename = new Ext.form.ComboBox({
								id : 'currentstatename',
								editable : false,
								typeAhead : true,
								triggerAction : 'all',
								lazyRender : true,
                                fieldLabel:'当前阶段名称',
								emptyText : '请选择当前阶段名称',
								// autoWidth : true,
								width : 150,
								mode : 'local',
								/** Fix此处按需改成googlesuggest模式 */
								store : new Ext.data.ArrayStore({
											id : 1,
											fields : ['currentstatename'],
											data : [['信息中心（受理）'],
													['信息中心（不受理）'],
													['信息中心（提交中）']]
										}),
								valueField : 'currentstatename',
								displayField : 'currentstatename'

							});

					var Teventstate =new Ext.form.ComboBox({
                                id : 'eventstate',
                                editable : false,
                                typeAhead : true,
                                triggerAction : 'all',
                                lazyRender : true,
                                emptyText : '请选择问题状态',
                                fieldLabel:'问题状态',
                                width : 150,
                                mode : 'local',
                                /** Fix此处按需改成googlesuggest模式 */
                                store : new Ext.data.ArrayStore({
                                            id : 1,
                                            fields : ['eventstate'],
                                            data : [['立案提交'],
                                                    ['立案未提交'],
                                                    ['其他']]
                                        }),
                                valueField : 'eventstate',
                                displayField : 'eventstate'
                            }); 
                 
					var form = new Ext.form.FormPanel({
						width : 350,
						labelAlign : "right",
						frame : true,
						items : [TproblemID, TareaID, TrecID, TeventsrcID,
								Teventsrc, Teventsubsrc, Teventtype,
								Tbigcategory, Tsmallcategory, Tsubcategory,
								Tcurrentstatename, Teventstate],
						url : "problem?method=edit",
						buttonAlign : "center",
						method : "post",
						buttons : [{
							text : "问题修改",
							icon : "extjsLib/resources/static/images/default/dd/disk.png",
							handler : function() {
								var json = {
									success : function(form, action) {
										var msg = action.result.msg;
										if (msg == "yes") {
											Ext.Msg.alert("成功", "信息修改成功！");
											win.close();
											problemstore.reload();
										} else {
											Ext.Msg.alert("失败", "信息修改异常！");
										}
									}
								};
								form.getForm().submit(json);
								problemstore.reload();
							}
								// win.close();
						}, {
							text : "关闭",
							icon : "extjsLib/resources/static/images/default/dd/delete.gif",
							handler : function() {
								win.close();
							}
						}]
					});
					var win = new Ext.Window({
								title : "问题修改",
								id : "edit",
								// width : 500,
								width : 350,
								modal : true,
								autoHeight : true,
								items : [form]
							});
					win.show();

					// set the form default values
					form.getForm().setValues({
								"problemID" : record.get("eventcauseID"),
								"areaID" : record.get("areaID"),
								"eventsrcID" : record.get("eventsrcID"),
								"eventsrc" : record.get("eventsrc"),
								"eventsubsrc" : record.get("eventsubsrc"),
								"eventtype" : record.get("eventtype"),
								"bigcategory" : record.get("bigcategory"),
								"smallcategory" : record.get("smallcategory"),
								"subcategory" : record.get("subcategory"),
								"currentstatename" : record
										.get("currentstatename"),
								"eventstate" : record.get("eventstate")
							});
				}
			}
		}, {
			xtype : "tbseparator"
		}, {
			pressed : false,
			text : '所有问题',
			icon : "static/images/table_refresh.png",
			handler : function() {
				problemstore.proxy = aaProxy;
				problemstore.load({
							params : {
								start : 0,
								limit : 11
							}
						});
			}
		}, {
			xtype : "tbseparator"
		}, '查询:', new Ext.form.ComboBox({
					id : 'typedetail',
					editable : true,
					typeAhead : true,
					triggerAction : 'all',
					lazyRender : true,
					emptyText : '请选择查询类型',
					// autoWidth : true,
					width : 150,
					mode : 'local',
					store : new Ext.data.ArrayStore({
								id : 1,
								fields : ['searchtype', 'typedetail'],
								data : [['大类', 'bigcategory'],
										['小类', 'smallcategory'],
										['子类', 'subcategory']]
							}),
					valueField : 'typedetail',
					displayField : 'searchtype'
				}), new Ext.form.Field({
					id : 'searchDetails',
					emptyText : '请输入查询信息',
					width : 150
				}), {
			text : '确认',
			icon : "static/image/repair.png",
			handler : function() {
				var searchDetails = Ext.getCmp('searchDetails').getValue();
				var searchType = Ext.getCmp('typedetail').getValue();
				problemstore.proxy = searchProxy;
				problemstore.baseParams = {
					detail : searchDetails,
					searchType : searchType
				};
				problemstore.load({
							params : {
								start : 0,
								limit : 11
							}
						});

			}
		}],
		bbar : [new Ext.PagingToolbar({
					store : problemstore,
					displayInfo : true,
					pageSize : 11,
					beforePageText : "当前第",
					afterPageText : "页，共{0}页",
					lastText : "尾页",
					nextText : "下一页",
					prevText : "上一页",
					firstText : "首页",
					refreshText : "刷新页面",
					displayInfo : true,
					displayMsg : "当前显示 {0} - {1}条, 共 {2}",
					emptyMsg : "没有记录"
				})]
	});
	var win = new Ext.Panel({
				layout : 'border',
				height : height,
				width : width,
				items : [problempp]
			});
	win.render(Ext.getBody());
});